<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>期刊论文管理系统 - 注册</title>

    <!-- 引入Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <style>
        body {
            background-image: url('images/background.jpg');
            background-size: cover;
            background-position: center;
            font-family: 'Roboto', sans-serif;
            height: 100vh;
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .container {
            background-color: rgba(255, 255, 255, 0.9);
            padding: 40px;
            border-radius: 15px;
            max-width: 400px;
            width: 100%;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }

        h2, h4 {
            font-weight: 600;
            color: #333;
        }

        .form-group input {
            font-size: 16px;
            padding: 12px;
            border-radius: 8px;
            border: 1px solid #ddd;
            margin-bottom: 15px;
            width: 100%;
        }

        .form-group input:focus {
            border-color: #007bff;
            box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
        }

        .btn {
            border-radius: 25px;
            padding: 12px;
            font-size: 18px;
            width: 100%;
            transition: all 0.3s ease;
        }

        .btn-primary {
            background: linear-gradient(90deg, #00b4db, #0083b0);
            border: none;
            color: white;
        }

        .btn-primary:hover {
            background: linear-gradient(90deg, #0083b0, #00b4db);
            transform: translateY(-3px);
        }

        .footer {
            position: fixed;
            bottom: 10px;
            width: 100%;
            text-align: center;
            color: #ddd;
        }

        .footer p {
            margin: 0;
            font-size: 14px;
        }

        p.text-center {
            font-size: 16px;
        }

        p.text-center a {
            text-decoration: none;
            color: #007bff;
            font-weight: bold;
        }

        p.text-center a:hover {
            color: #0056b3;
        }

    </style>
</head>
<body>

<div class="container">
    <h2 class="text-center mb-4">期刊论文管理系统</h2>
    <h4 class="text-center mb-4">用户注册</h4>

    <!-- 注册表单 -->
    <form id="registerForm">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" class="form-control" id="username" placeholder="请输入用户名" required>
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" class="form-control" id="password" placeholder="请输入密码" required>
        </div>
        <div class="form-group">
            <label for="password2">确认密码</label>
            <input type="password" class="form-control" id="password2" placeholder="请再次输入密码" required>
        </div>
        <button type="submit" class="btn btn-primary">注册</button>
    </form>

    <p class="text-center mt-3">
        已有账户？ <a href="login.html">登录</a>
    </p>
</div>

<!-- 引入Bootstrap和jQuery JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.2/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

<script>
    document.getElementById("registerForm").addEventListener("submit", function(event) {
        event.preventDefault();

        var username = document.getElementById('username').value;
        var password = document.getElementById('password').value;
        var password2 = document.getElementById('password2').value;

        // 密码校验
        if (password !== password2) {
            alert('两次输入的密码不一致！');
            return;
        }

        if (!username || !password || !password2) {
            alert('用户名或密码不能为空！');
            return;
        }

        // 注册请求
        fetch('http://127.0.0.1:8080/user/register', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({ username: username, password: password })
        })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    // 注册成功后跳转到登录页面
                    window.location.href = 'login.html';
                } else {
                    alert('注册失败，请稍后再试');
                }
            })
            .catch(error => {
                console.log(error);
                alert('服务器错误，请等待修复');
            });
    });
</script>

</body>
</html>
